import Vue from 'vue'
import Vuex from 'vuex'
import settings from "@/settings.js"
import user from '@/store/modules/user'
import order from '@/store/modules/order'
import station from '@/store/modules/station'
import voucher from '@/store/modules/voucher'
import coupon from '@/store/modules/coupon'
import point from '@/store/modules/point'

Vue.use(Vuex)
export default new Vuex.Store({
  state: {
    appId: settings.appId,
    enterpriseId :settings.enterpriseId,
    // stationId: settings.stationId,
    // phoneNumber:uni.getStorageSync('phoneNumber') || "",
    // countryCode:uni.getStorageSync('countryCode') || "",
    // purePhoneNumber:uni.getStorageSync('purePhoneNumber') || "",
    // openId: uni.getStorageSync('openId') || "",
    // unionId: uni.getStorageSync('unionId') || "",
    // userInfo: !uni.getStorageSync('userInfo') ? {} : JSON.parse(uni.getStorageSync('userInfo')),
    // orderInfo:undefined,
    // selectedGun:undefined,
    // labelId:undefined,
    // employeeId:undefined,
  },
  getters: {
  },
  mutations: {
    updateEnterpriseId(state, enterpriseId) {
      console.log(enterpriseId, 'enterpriseIdenterpriseId');
      uni.setStorageSync('enterpriseId', enterpriseId);
      state.enterpriseId = enterpriseId
    },
    // updateCountryCode(state, countryCode) {
    //   uni.setStorageSync('countryCode', countryCode);
    //   state.countryCode = countryCode
    // },
    // updatePurePhoneNumber(state, purePhoneNumber) {
    //   uni.setStorageSync('phoneNumber', phoneNumber);
    //   state.purePhoneNumber = purePhoneNumber
    // },
    // updateOpenId(state, openId) { 
    //   uni.setStorageSync('openId', openId);
    //   state.openId = openId
    // },
    // updateUnionId(state, unionId) {
    //   uni.setStorageSync('unionId', unionId);
    //   state.unionId = unionId
    // },
    
    // clearUserAuthen(state){
    //   uni.removeStorageSync('phoneNumber')
    //   uni.removeStorageSync('countryCode')
    //   uni.removeStorageSync('purePhoneNumber')
    //   uni.removeStorageSync('openId')
    //   uni.removeStorageSync('unionId')
    //   state.phoneNumber = ''
    //   state.countryCode = ''
    //   state.purePhoneNumber = ''
    //   state.openId = ''
    //   state.unionId = ''
    // },
    
    // updateUserInfo(state, userInfo) {      
    //   uni.setStorageSync('userInfo', JSON.stringify(userInfo));
    //   state.userInfo = userInfo
    // },
    // clearUserInfo(state) {
    //   uni.removeStorageSync('userInfo')
    //   state.userInfo = {}
    // },
    
    // updateOrderInfo(state, orderInfo){
    //   state.orderInfo = orderInfo
    // },
    // updateSelectedGun(state, selectedGun){
    //   state.selectedGun = selectedGun
    // },
    // updateStationId(state, stationId){
    //   state.stationId = stationId
    // },
    // updateLabelId(state, labelId) {
    //   state.labelId = labelId
    // },
    // clearLabelId(state){
    //   state.labelId = undefined
    // },
    resetApplet(state){
      console.log('ok---------')
      uni.clearStorageSync()
      state.user.phoneNumber = undefined
      state.user.countryCode = undefined
      state.user.purePhoneNumber = undefined
      state.user.openId = undefined
      state.user.unionId = undefined
      state.user.userId = undefined
      state.user.userInfo = {}
      state.station.employeeId = undefined
      state.station.userScan = {
        gunName: undefined,
        receivableAmt: undefined,
        orderRandomId: undefined,
        orderOriginType: undefined,
      },
      state.station.stationPayPush = undefined
    },
    // updateEmployeeId(state, employeeId){
    //   state.employeeId = employeeId
    // },
    // clearEmployeeId(state){
    //   state.employeeId = undefined
    // }
  },
  actions: {

  },
  modules: {
    user,
    order,
    station,
    voucher,
    coupon,
    point
  }
})
